/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-06
 * Time: 15:13
 */
public class Demo8 {
    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            while(true) {
                System.out.println("hello thread!");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        //主线程结束的同时整个程序都结束就要在start方法之前将t线程设置为后台线程
        //t.setDaemon(true);
        t.start();
        //t.setDaemon(true);//IllegalThreadStateException

        for (int i = 0; i < 3; i++) {
            System.out.println("hello main!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("main结束");
    }
}
